package cn.kgc.qyf.gentelella.web;

import cn.kgc.qyf.gentelella.entity.BackendUser;
import cn.kgc.qyf.gentelella.service.BackendUserService;
import cn.kgc.qyf.gentelella.service.Constant;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession;

import javax.annotation.Resource;
import java.util.Date;

@Controller
public class LogInOutController {

    @Resource
    private BackendUserService backendUserService;
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/doLogin")
    public String doLogin(String userCode,String userPassword,HttpSession session){
        BackendUser backendUser=this.backendUserService.findUser(userCode,userPassword);
        if (backendUser!=null){
            session.setAttribute(Constant.USER,backendUser);
            return "redirect:toForm";
        }
        return "redirect:toLogin?flag=-1";
    }

    @RequestMapping("/toForm")
    public String toFrame(){
        return "form";
    }

}
